package com.iyundao.io.mapper;

import com.iyundao.io.model.SysUserInfo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.UpdateProvider;
import org.apache.ibatis.type.JdbcType;
import org.springframework.stereotype.Repository;

@Repository
public interface SysUserInfoMapper {
    @Delete({
        "delete from sys_user_info",
        "where sid = #{sid,jdbcType=CHAR}"
    })
    int deleteByPrimaryKey(String sid);

    @Insert({
        "insert into sys_user_info (sid, uid, openid, ",
        "unionid, nickname, ",
        "avatarUrl, gender, ",
        "city, province, ",
        "country, language)",
        "values (#{sid,jdbcType=CHAR}, #{uid,jdbcType=CHAR}, #{openid,jdbcType=VARCHAR}, ",
        "#{unionid,jdbcType=VARCHAR}, #{nickname,jdbcType=VARCHAR}, ",
        "#{avatarurl,jdbcType=VARCHAR}, #{gender,jdbcType=VARCHAR}, ",
        "#{city,jdbcType=VARCHAR}, #{province,jdbcType=VARCHAR}, ",
        "#{country,jdbcType=VARCHAR}, #{language,jdbcType=VARCHAR})"
    })
    int insert(SysUserInfo record);

    @InsertProvider(type=SysUserInfoSqlProvider.class, method="insertSelective")
    int insertSelective(SysUserInfo record);

    @Select({
        "select",
        "sid, uid, openid, unionid, nickname, avatarUrl, gender, city, province, country, ",
        "language",
        "from sys_user_info",
        "where sid = #{sid,jdbcType=CHAR}"
    })
    @Results({
        @Result(column="sid", property="sid", jdbcType=JdbcType.CHAR, id=true),
        @Result(column="uid", property="uid", jdbcType=JdbcType.CHAR),
        @Result(column="openid", property="openid", jdbcType=JdbcType.VARCHAR),
        @Result(column="unionid", property="unionid", jdbcType=JdbcType.VARCHAR),
        @Result(column="nickname", property="nickname", jdbcType=JdbcType.VARCHAR),
        @Result(column="avatarUrl", property="avatarurl", jdbcType=JdbcType.VARCHAR),
        @Result(column="gender", property="gender", jdbcType=JdbcType.VARCHAR),
        @Result(column="city", property="city", jdbcType=JdbcType.VARCHAR),
        @Result(column="province", property="province", jdbcType=JdbcType.VARCHAR),
        @Result(column="country", property="country", jdbcType=JdbcType.VARCHAR),
        @Result(column="language", property="language", jdbcType=JdbcType.VARCHAR)
    })
    SysUserInfo selectByPrimaryKey(String sid);

    @UpdateProvider(type=SysUserInfoSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(SysUserInfo record);

    @Update({
        "update sys_user_info",
        "set uid = #{uid,jdbcType=CHAR},",
          "openid = #{openid,jdbcType=VARCHAR},",
          "unionid = #{unionid,jdbcType=VARCHAR},",
          "nickname = #{nickname,jdbcType=VARCHAR},",
          "avatarUrl = #{avatarurl,jdbcType=VARCHAR},",
          "gender = #{gender,jdbcType=VARCHAR},",
          "city = #{city,jdbcType=VARCHAR},",
          "province = #{province,jdbcType=VARCHAR},",
          "country = #{country,jdbcType=VARCHAR},",
          "language = #{language,jdbcType=VARCHAR}",
        "where sid = #{sid,jdbcType=CHAR}"
    })
    int updateByPrimaryKey(SysUserInfo record);
}